define(['jquery', 'bootstrap', 'backend', 'table', 'form',  'bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form,Jump) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'activity/apply/index' + location.search,
                    add_url: 'activity/apply/add',
                    edit_url: 'activity/apply/edit',
                    del_url: 'activity/apply/del',
                    multi_url: 'activity/apply/multi',
                    table: 'activity_apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: false,
                showJumpto: true,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'activityitem.name', title: '活动名称', operate: 'like'},
                        {field: 'user.nickname', title: '昵称', operate: 'like'},
                        {field: 'user.mobile', title: '电话', operate: 'like'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'check', title: __('Check'), searchList: {"0":__('Check 0'),"1":__('Check 1'),"2":__('Check 2')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [

                                {
                                    name: 'remark',
                                    text: '审核',
                                    title: '审核',
                                    classname: 'btn btn-xs btn-info btn-click',
                                    icon: 'fa fa-hand-o-up',
                                    hidden: function(row) {
                                        if (row.check == 0) {
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                    click: function (event, data) {
                                        Layer.confirm("<form id='check-piliang' class='form-horizontal'  action='' method='post'>" +
                                            "<textarea class='form-control' rows='3' name='remark'></textarea>" +
                                            "</form>",
                                            {
                                                title: '审核申请',
                                                btn: ["确定", "决绝"],
                                                yes: function (index, layero) {
                                                    Fast.api.ajax({
                                                        url: 'activity/apply/check',
                                                        data: {
                                                            id: data.id,
                                                            type: 1,
                                                            remark: $("textarea[name=remark]", layero).val(),
                                                        }
                                                    }, function (ret) {
                                                        Layer.close(index);
                                                        $(".btn-refresh").trigger("click");
                                                    });
                                                    return false;
                                                },
                                                btn2: function (index, layero) {
                                                    Fast.api.ajax({
                                                        url: 'activity/apply/check',
                                                        data: {
                                                            id: data.id,
                                                            type: 2,
                                                            remark: $("textarea[name=remark]", layero).val(),
                                                        }
                                                    }, function (ret) {
                                                        Layer.close(index);
                                                        $(".btn-refresh").trigger("click");
                                                    });

                                                }
                                            } )
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});